home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / dtkclk11.zip / READCLK.C < prev    next >
Text File  |  1993-05-06  |  2KB  |  92 lines

  1. /*
  2.  * Program to read the time from the DTK clock/calendar board.
  3.  * (C) Copyright 1989 Richard B. Wales.  All Rights Reserved.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "clkdefs.h"
  8.  
  9.  
  10. static char copyright[] =
  11. "READCLK -- Read DTK clock/calendar board, version 1.10\r\n\
  12. (C) Copyright 1989 Richard B. Wales";
  13.  
  14.  
  15. void main (int argc, char **argv)
  16. {    struct clockval *cv;
  17.     struct date *da;
  18.     struct time *ti;
  19.     int freeze_offset;
  20.  
  21.     /*
  22.      * Identify the program.
  23.      */
  24.     printf ("%s\n", copyright);
  25.  
  26.     /*
  27.      * If there is an argument, convert it into a number.
  28.      * This number of seconds will be added to the value
  29.      * read from the clock board before setting the system time.
  30.      * This overcomes a hardware misfeature that causes the
  31.      * board to "freeze" at power-up.  The number of seconds
  32.      * should be set equal to however long your system takes
  33.      * to get to the READCLK command in AUTOEXEC.BAT after a
  34.      * power-up.
  35.      */
  36.     if (argc > 1)
  37.         freeze_offset = atoi (argv[1]);
  38.     else    freeze_offset = 0;
  39.  
  40.     /*
  41.      * Read the clock/calendar board.
  42.      */
  43.     cv = read_clock ();
  44.     if (cv == NULL_CLOCK)
  45.     {    printf ("Error reading clock\n");
  46.         exit (1);
  47.     }
  48.  
  49.     /*
  50.      * Add the "frozen boot interval" correction.
  51.      * If the byte at 0040:0072 is 034H, however,
  52.      * this is a "warm boot"; skip this correction.
  53.      */
  54.     if (freeze_offset > 0
  55.         && *((unsigned char far *)0x00472L) != 0x34)
  56.     {       advance_time (cv, freeze_offset);
  57.         if (write_clock (cv) == NULL_CLOCK)
  58.         {    printf ("%s %s\n",
  59.                 "Couldn't rewrite clock with",
  60.                 "frozen boot offset");
  61.             exit (1);
  62.         }
  63.                 cv = read_clock ();
  64.         if (cv == NULL_CLOCK)
  65.         {    printf ("Error re-reading clock\n");
  66.             exit (1);
  67.     }    }
  68.  
  69.     /*
  70.      * Set the system date and time.
  71.      */
  72.     clock_to_time (cv, &da, &ti);
  73.     if (da == NULL_DATE || ti == NULL_TIME)
  74.     {    printf ("Garbled date/time from clock\n");
  75.         exit (1);
  76.     }
  77.     settime (ti); setdate (da);
  78.  
  79.     /*
  80.      * Announce the new date and time.
  81.      */
  82.     gettime (ti); getdate (da);
  83.     printf ("New date/time is %02d/%02d/%02d %02d:%02d:%02d\n",
  84.         da->da_mon, da->da_day, da->da_year % 100,
  85.         ti->ti_hour, ti->ti_min, ti->ti_sec);
  86.  
  87.     /*
  88.      * That's all.
  89.      */
  90.     exit (0);
  91. }
  92.